package com.school.adapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.xml.transform.Templates;

import com.school.activity.R;
import com.school.domain.BookBorrow;
import com.school.domain.Grade;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
/**
 * @author lp
 *
 */
public class BookBorrowExpandAdapter extends BaseExpandableListAdapter{

	private List<BookBorrow> bookBorrows;
	private Context context;

	public BookBorrowExpandAdapter(Context context,
			List<BookBorrow> bookBorrows) {
		this.context=context;
		this.bookBorrows=bookBorrows;
	}

	public void setBookBorrows(List<BookBorrow> bookBorrows) {
		this.bookBorrows = bookBorrows;
	}

	@Override
	public int getGroupCount() {
		return 1;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		return bookBorrows.size();
	}

	@Override
	public Object getGroup(int groupPosition) {
		return null;
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		return null;
	}

	@Override
	public long getGroupId(int groupPosition) {
		return groupPosition;
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		return childPosition;
	}

	@Override
	public boolean hasStableIds() {
		return true;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		if(convertView==null){
			convertView=(RelativeLayout) LayoutInflater.from(context).
					inflate(R.layout.expand_listview_book_borrow_group, null);
		} 
		if(isExpanded){
			((ImageView)convertView.findViewById(R.id.book_borrow_list_arrow)).setImageResource(R.drawable.icon_details_down);
		}else{
			((ImageView)convertView.findViewById(R.id.book_borrow_list_arrow)).setImageResource(R.drawable.icon_details);	
		}
		return convertView;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		if(convertView==null){
			convertView=(RelativeLayout) LayoutInflater.from(context).
					inflate(R.layout.expand_listview_book_borrow_child, null);
		}
		BookBorrow bookBorrow=bookBorrows.get(childPosition);
		((TextView)convertView.findViewById(R.id.book_borrow_name)).setText(bookBorrow.getBookNameAuthor());
		((TextView)convertView.findViewById(R.id.book_borrow_date)).setText(bookBorrow.getBookDate());
		((TextView)convertView.findViewById(R.id.book_borrow_place)).setText(bookBorrow.getBookPlace());
		return convertView;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		return true;
	}

}
